package site.shader85.OICQBind;

import java.util.HashMap;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.inventory.InventoryInteractEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import static site.shader85.OICQBind.BindPlugin.registeredConfig;

public class BindingListener implements Listener{
	
	public static HashMap<Player,Integer> unregisteredPlayers = new HashMap<Player,Integer>();
	
	@EventHandler
	public void onPlayerLogin(PlayerJoinEvent evt){
		Player player = evt.getPlayer();
		if(!registeredConfig.contains(player.getName())){
			unregisteredPlayers.put(player,0);
		}
	}
	
	@EventHandler
	public void onPlayerMoving(PlayerMoveEvent evt){
		if(unregisteredPlayers.containsKey(evt.getPlayer()))
			evt.setCancelled(true);
	}
	
	@EventHandler
	public void onPlayerDamaged(EntityDamageEvent evt){
		if(unregisteredPlayers.containsKey(evt.getEntity()))
			evt.setCancelled(true);
	}
	
	@EventHandler
	public void onPlayerDamaging(EntityDamageByEntityEvent evt){
		if(unregisteredPlayers.containsKey(evt.getDamager())){
			evt.setCancelled(true);
		}
	}
	
	@EventHandler
	public void onBlockBreaking(BlockBreakEvent evt){
		if(unregisteredPlayers.containsKey(evt.getPlayer()))
			evt.setCancelled(true);
	}
	
	@EventHandler
	public void onBlockDamaged(BlockDamageEvent evt){
		if(unregisteredPlayers.containsKey(evt.getPlayer()))
			evt.setCancelled(true);
	}
	
	@EventHandler
	public void onChestOpen(InventoryInteractEvent evt){
		if(unregisteredPlayers.containsKey(evt.getWhoClicked()))
			evt.setCancelled(true);
	}
	
	@EventHandler
	public void onCMD(AsyncPlayerChatEvent evt){
		if(unregisteredPlayers.containsKey(evt.getPlayer()))
			evt.setCancelled(true);
	}
	@EventHandler
	public void onPlayerQuit(PlayerQuitEvent evt){
		unregisteredPlayers.remove(evt.getPlayer());
	}
}
